package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28779
 * Date: 2023-08-21
 * Time: 11:46
 */
class Counter {
    public static int count = 0;
    public Object adc = new Object();
    synchronized public void increase1() {
        count ++;
    }

    public void increase2() {
        synchronized (this) {
            count ++;
        }
    }
    public void increase3() {
        synchronized (adc) {
            count ++;
        }
    }
    public void increase4() {
        synchronized (this) {
            count --;
        }
    }

}
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Counter counter = new Counter();
        Thread t1 = new Thread(() -> {
            for (int i = 0 ; i < 50000 ; i++) {
                counter.increase3();
            }
        });

        Thread t2 = new Thread(() -> {
            for (int i = 0 ; i < 50000 ; i++) {
                counter.increase4();
            }
        });

        t1.start();
        t1.join();

        t2.start();
        t2.join();

/*        t1.join();
        t2.join();*/

        System.out.println("count: " + counter.count);
    }
}
